﻿using System.Collections.Generic;

namespace TeamCityConfigurationMonitor.Core
{
    class ChangeProvider : IChangeProvider
    {
        private readonly object changesLock = new object();
        private readonly IList<FileSystemChange> changes = new List<FileSystemChange>();

        public IEnumerable<FileSystemChange> GetAndResetChanges()
        {
            lock (changesLock)
            {
                var localChanges = new FileSystemChange[changes.Count];
                changes.CopyTo(localChanges, 0);
                changes.Clear();
                return localChanges;
            }
        }

        public void CollectChange(FileSystemChange fileSystemChange)
        {
            lock (changesLock)
                changes.Add(fileSystemChange);
        }
    }
}